import { _decorator, clamp01, Component, Node, UITransform } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('ProgressBar')
export class ProgressBar extends Component {
    @property(Node) ndBg: Node;
    @property(Node) ndFill: Node;
    private _maxWidth: number = 1;

    protected onLoad(): void {
        this._maxWidth = this.ndFill.getComponent(UITransform).contentSize.width;
    }

    protected onEnable(): void {
        
    }
    protected onDisable(): void {
        
    }
    start() {

    }

    update(deltaTime: number) {
        
    }
    

    setProgress(progress:number) { // {0,1}
        progress = clamp01(progress);
        const transform = this.ndFill.getComponent(UITransform);
        transform.setContentSize(this._maxWidth * progress, transform.contentSize.height);
    }
}


